<?php

/**
 * @author Anh Nguyen <duyanhnguyen@vccorp.vn>
 * @copyright 2012
 */

class DefaultLayout
{
    
    private $_CI;
    private $_langCode;
    private $_module;
    private $_headInfo = array();

    function __construct()
    {
        $this->_CI =& get_instance();
        $this->_langCode = $this->_CI->mycommon->getLangCode();
        $this->_module = $this->_CI->router->fetch_module();
        $this->_CI->load->library('Blockcache');
        $this->_CI->load->library('Minifier');
        $this->_CI->load->language('common', $this->_langCode);
        $common_lang = $this->_CI->lang->line('default_lang_common');
        $configBread = array(
            'seperator'     =>      ' &raquo; ',
            'home_text'     =>      $common_lang['hometext_breadcrumb'],
        );
        $this->_CI->load->library('Breadcrumb', $configBread);
        $headInfo = $this->_CI->lang->line('head_infomation');
        $this->_headInfo = array(
            'head_title'            =>          $headInfo['head_title'],
            'head_keywords'         =>          $headInfo['head_keywords'],
            'head_description'      =>          $headInfo['head_description'],
            'head_author'           =>          $headInfo['head_author'],
        );
        $this->setCssJs();
    }
    
    private function setCssJs()
    {
        $this->_CI->minifier->AddCss('basic');
        $this->_CI->minifier->AddCss('grid');
        $this->_CI->minifier->AddCss('layout');
        $this->_CI->minifier->AddCss('module');
        $this->_CI->minifier->AddCss('structure');
        $this->_CI->minifier->AddJs('jquery-1.7.2.min');
        $this->_CI->minifier->AddJs('custom');
    }
    
    public function _loadHeader($title = '')
    {
        $data = array();
        $data['head_title'] = ($title != '') ? $title : $this->_headInfo['head_title'];
        $data['head_keywords'] = $this->_headInfo['head_keywords'];
        $data['head_description'] = $this->_headInfo['head_description'];
        $data['head_author'] = $this->_headInfo['head_author'];
        $data['combinedCss'] = $this->_CI->minifier->GetCombined('css');
        $data['combinedJs'] = $this->_CI->minifier->GetCombined('js');
        $data['common_lang'] = $this->_CI->lang->line('default_lang_common');
        $data['langCode'] = $this->_CI->mycommon->fetchLangCode($this->_langCode);
        $this->_CI->load->model('landing/landing_model');
        $data['category'] = array();
        $parentCat = $this->_CI->landing_model->getCategory(0, $data['langCode']);
        foreach ($parentCat as $v) {
            $data['category'][$v['id']]['name'] = $v['name'];
            $data['category'][$v['id']]['childCat'] = array();
            $tmpCat = $this->_CI->landing_model->getCategory($v['id'], $data['langCode']);
            foreach ($tmpCat as $k) {
                $data['category'][$v['id']]['childCat'][$k['id']]['name'] = $k['name'];
            }
        }
        $this->_CI->load->view('header_view', $data);
    }
    
    public function _loadFooter()
    {
        $data = array();
        $data['common_lang'] = $this->_CI->lang->line('default_lang_common');
        $this->_CI->load->view('footer_view', $data);
    }
    
    public function setHeadInfo($data = array())
    {
        $this->_headInfo['head_title'] = (isset($data['head_title']) && $data['head_title'] != '') ? $data['head_title'] : $this->_headInfo['head_title'];
        $this->_headInfo['head_keywords'] = (isset($data['head_keywords']) && $data['head_keywords'] != '') ? $data['head_keywords'] : $this->_headInfo['head_keywords'];
        $this->_headInfo['head_description'] = (isset($data['head_description']) && $data['head_description'] != '') ? $data['head_description'] : $this->_headInfo['head_description'];
        $this->_headInfo['head_author'] = (isset($data['head_author']) && $data['head_author'] != '') ? $data['head_author'] : $this->_headInfo['head_author'];
    }
    
    

}

?>
